﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Fcdbas.WinUI.Controls
{
    public partial class ImageAndText : DevExpress.XtraEditors.XtraUserControl
    {
        public event EventHandler SelectImage;
        public ImageAndText()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.Selectable, true);
            cPicture.Click += new EventHandler(cPictureEdit1_Click);
            cPicture.IsUserKey = false;
            cPicture.KeyDown += new KeyEventHandler(cPicture_KeyDown);
            cPicture.LostFocus += new EventHandler(cPicture_LostFocus);
            cPicture.GotFocus += new EventHandler(cPicture_GotFocus);
            cPicture.KeyUp += new KeyEventHandler(cPicture_KeyUp);
        }

        void cPicture_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == (Keys.LButton | Keys.ShiftKey))
                _isMulSelected = false;
            OnKeyUp(e);
        }
        private bool _isMulSelected;
        public bool IsMulSelected
        {
            get
            {
                return _isMulSelected;
            }
            set
            {
                if (value)
                    this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                else
                    this.BorderStyle = System.Windows.Forms.BorderStyle.None;
                _isMulSelected = value;
            }
        }
        void cPicture_GotFocus(object sender, EventArgs e)
        {
            OnGotFocus(e);
        }

        void cPicture_LostFocus(object sender, EventArgs e)
        {
            OnLostFocus(e);
        }

        void cPicture_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == (Keys.LButton | Keys.ShiftKey))
                _isMulSelected = true;
            OnKeyDown(e);
        }
        protected override bool IsInputKey(System.Windows.Forms.Keys keyData)
        {
            if ((keyData & Keys.Alt) == Keys.Alt)
            {
                return false;
            }
            switch ((keyData & Keys.KeyCode))
            {
                case Keys.Up:
                case Keys.Down:
                    return true;
            }
            return base.IsInputKey(keyData);
        }
        void cPictureEdit1_Click(object sender, EventArgs e)
        {
            if (SelectImage != null)
                SelectImage.Invoke(this, EventArgs.Empty);
            this.Focus();
            _isSelected = true;

        }
        public string ImagePath
        {
            set
            {
                if (!System.IO.File.Exists(value))
                    return;
                cPicture.Image = Image.FromFile(value);
            }
        }
        public bool TagVisible
        {
            get
            {
                return lbTag.Visible;
            }
            set
            {
                lbTag.Visible = value;
            }
        }
        public string TagValue
        {
            get
            {
                return lbTag.Text;
            }
            set
            {
                lbTag.Text = value;
            }
        }
        public Image CurrentImage
        {
            get
            {
                return cPicture.Image;
            }
            set
            {
                cPicture.Image = value;
            }
        }
        public string ImageText
        {
            set
            {
                this.cLabel1.Text = value;
            }
            get
            {
                return this.cLabel1.Text;
            }
        }
        private bool _isSelected;
        public bool IsSelected
        {
            get
            {
                return _isSelected;
            }
            set
            {
                if (value)
                    this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                else
                    this.BorderStyle = System.Windows.Forms.BorderStyle.None;
                _isSelected = value;
            }
        }
        public bool ShowMenu
        {
            get
            {
                return this.cPicture.Properties.ShowMenu;
            }
            set
            {
                this.cPicture.Properties.ShowMenu = value;
            }
        }
    }
}
